﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using DEVINO.Lib;


namespace SmsVotes
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //if (Request.UserHostAddress == "127.0.0.1")
                //{
                //    Authenticate("0000_1test", "test");
                //}
                string userLogin = Request.QueryString["Login"];
                string clientID = Request.QueryString["ClientID"];
                string password = Request.QueryString["Password"];
                if (userLogin != null && password != null)
                {
                    txtUserLogin.Text = userLogin;
                    txtClientID.Text = clientID;
                    Authenticate(clientID + "_" + userLogin, password);
                }
            }
        }

        private void Authenticate(string userLogin, string password)
        {
            string sessionID;
            //SecurityManager.SecurityManager sm = new SmsVotes.SecurityManager.SecurityManager();
            //SmsVotes.SecurityManager.CommandStatus commandStatus = sm.Authenticate(SmsVotes.SecurityManager.AccessType.Web, userLogin, password, Request.UserHostAddress, out sessionID);
            //if (commandStatus != SmsVotes.SecurityManager.CommandStatus.OK_Operation_Completed)
            //{
            //    lblResult.Text = "Некорректный логин или пароль";
            //    return;
            //}
            //FormsAuthentication.SetAuthCookie(userLogin, false);
            //Response.Redirect("SMSVoting.aspx");
        }

        protected void cmdSubmit_Click(object sender, EventArgs e)
        {
            if (!this.Page.IsValid)
            {
                return;
            }
            Authenticate(txtClientID.Text + "_" + txtUserLogin.Text, txtPassword.Text);
        }
    }
}
